package de.gameduell.framework.facebook {
	import de.gameduell.facebook.service.gen.Feature;
	import de.gameduell.framework.debug.Debug;

	import flash.events.Event;
	import flash.events.EventDispatcher;

	/**
	 * @author meue
	 */
	public class FeatureList extends EventDispatcher{
		
		// TODO: maybe on 2015 use Vector<Feature>, when everyone uses Flashplayer 10 ;-)
		private var features:Array = new Array();
		public static var FEATURES_LOADED:String= "FEATURES LOADED";
		
		public function isEnabled(featureId:int):Boolean{
			for(var i:int = 0;i< features.length;i++){
				var f:Feature = Feature(features[i]); 
				if(f.definitionId == featureId) {
					return f.enabled;
				}
			}
			return false;
		}
		
		public function getCatalogItemId(featureId:int):int{
			for(var i:int = 0;i< features.length;i++){
				var f:Feature = Feature(features[i]); 
				if(f.definitionId == featureId) {
					return f.catalogItemId;
				}
			}
			return -1;
		}
		
		public function isCatalogItemIdEnabled(catalogItemId:int):Boolean{
			for(var i:int = 0;i< features.length;i++){
				var f:Feature = Feature(features[i]);
				if(f.enabled){
					if(f.catalogItemId == catalogItemId) {
						return true;
					}
				}
			}
			return false;
		}
		
		public function addFeature(feature:Feature):void{
			features.push(feature);
		}
		
		public function setFeatures(someFeatures:Array):void{
			features = someFeatures;
			for each(var myFeature:Feature in features){
				Debug.trace("FeatureList::setFeatures: myFeature: " + myFeature.definitionId + ":" + myFeature.enabled + ":" + myFeature.name + " CATALOG -> :" + myFeature.hasCatalogItemOption + ":" + myFeature.catalogItemId, Debug.DEBUG);
			}
			dispatchEvent(new Event(FEATURES_LOADED));
		}
	}
}